const mysql = require('mysql2/promise');

//创建连接池

const pool = mysql.createPool({
        host            : '8.136.96.180',
        port            : '3306',
        user            : 'root',
        password        : 'Pin0802,',
        charset         : 'UTF8MB4_GENERAL_CI',
        multipleStatements: true,
        database: 'question'

})
//查询方法
const query = async (sql, values) => {

    let connection;

    try {

        connection = await pool.getConnection();

        const [results, fields] = await connection.execute(sql, values);

        return results;

    } catch (err) {

        throw err;

    } finally {

        connection.release();

    }

}

module.exports = { query }
